package com.ozo.cloud.common.feign.interceptor;

import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.util.StrUtil;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.stereotype.Component;

/**
 * feign请求拦截器
 *
 * @author qiangesoft
 * @date 2024-11-21
 */
@Component
public class FeignRequestInterceptor implements RequestInterceptor {

    @Override
    public void apply(RequestTemplate template) {
        try {
            String tokenValue = StpUtil.getTokenValue();
            if (StrUtil.isNotBlank(tokenValue)) {
                template.header(StpUtil.getTokenName(), tokenValue);
            }
        } catch (Exception e) {
//            e.printStackTrace();
        }
    }

}